package cn.livingCloud.entity.core;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.entity.user.Member;
import cn.livingCloud.entity.user.User;
import cn.livingCloud.repository.DeptMapper;
import cn.livingCloud.repository.MemberMapper;
import cn.livingCloud.utils.DateUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 员工
 */
public class Employee extends User {

    private transient DeptMapper deptMapper = BeanProvider.getBean(DeptMapper.class);
    private transient MemberMapper memberMapper = BeanProvider.getBean(MemberMapper.class);

    private String gender;

    private int age;

    private String phone;

    private String deptUuid;

    private boolean isLeader = false;

    private Date createDateTime = DateUtils.now();

    private boolean archive = false;

    private boolean inspector = false;

    public Employee() {
    }

    public String getGender() {
        return gender;
    }

    public Employee setGender(String gender) {
        this.gender = gender;
        return this;
    }

    public Integer getAge() {
        return age;
    }

    public Employee setAge(Integer age) {
        this.age = age;
        return this;
    }

    public String getPhone() {
        return phone;
    }

    public Employee setPhone(String phone) {
        this.phone = phone;
        return this;
    }

    public String getDeptUuid() {
        return deptUuid;
    }

    public Employee setDeptUuid(String deptUuid) {
        this.deptUuid = deptUuid;
        return this;
    }

    public boolean getIsLeader() {
        return isLeader;
    }

    public Employee setIsLeader(boolean isLeader) {
        this.isLeader = isLeader;
        return this;
    }

    public boolean isLeader() {
        return isLeader;
    }

    public Date getCreateDateTime() {
        return createDateTime;
    }

    public Employee setCreateDateTime(Date createDateTime) {
        this.createDateTime = createDateTime;
        return this;
    }

    public Boolean getArchive() {
        return archive;
    }

    public Employee setArchive(Boolean archive) {
        this.archive = archive;
        return this;
    }

    public Dept getDept() {
        return deptMapper.selectByPrimaryKey(this.deptUuid);
    }

    public List<String> getNickName() {
        List<String> list = new ArrayList<>();
        List<Member> members = memberMapper.findMemberByEmployeeUuid(this.uuid);
        for (Member member : members) {
            list.add(member.getNickname());
        }
        return list;
    }

    public boolean isInspector() {
        return inspector;
    }

    public Employee setInspector(boolean inspector) {
        this.inspector = inspector;
        return this;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "gender='" + gender + '\'' +
                ", uuid='" + this.getUuid() + '\'' +
                ", name='" + this.getName() + '\'' +
                ", age=" + age +
                ", phone='" + phone + '\'' +
                ", deptUuid='" + deptUuid + '\'' +
                ", isLeader=" + isLeader +
                ", createDateTime=" + createDateTime +
                ", archive=" + archive +
                ", inspector=" + inspector +
                '}';
    }
}